package com.wan.data.resource.parser;

import com.wan.core.strategy.StrategySelectorCreator;
import com.wan.core.strategy.selector.StrategyCustomMapSelector;

import java.util.Collection;

/**
 * @author wwh
 * @date 2022/7/4 20:38
 */
public class ParserSelectorCreator extends StrategySelectorCreator<String,ResourceParser, StrategyCustomMapSelector<String,ResourceParser>> {
    @Override
    protected StrategyCustomMapSelector<String, ResourceParser> newSelector(Collection<ResourceParser> objs) {
        return new StrategyCustomMapSelector<>(objs,
                map->{
                    for (ResourceParser parser : objs) {
                        String[] suffixes = parser.suffixes();
                        if(suffixes == null || suffixes.length == 0){
                            continue;
                        }
                        for (String suffix : suffixes) {
                            map.put(suffix,parser);
                        }
                    }
                });
    }
}
